package com.zzyl;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.AbstractCredentials;
import com.huaweicloud.sdk.core.auth.BasicCredentials;

import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.iotda.v5.*;
import com.huaweicloud.sdk.iotda.v5.model.*;
import com.zzyl.framework.config.properties.HuaWeiIotConfigProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class ListProductsSolution {
    @Autowired
    private HuaWeiIotConfigProperties huaWeiIotConfigProperties;

    @Test
    public void test01() {

        // 创建认证信息对象，用于后续请求的签名
        ICredential auth = new BasicCredentials()
                .withProjectId(huaWeiIotConfigProperties.getProjectId())
                // 标准版/企业版需要使用衍生算法，基础版请删除配置"withDerivedPredicate";
                .withDerivedPredicate(AbstractCredentials.DEFAULT_DERIVED_PREDICATE) // Used in derivative ak/sk authentication scenarios
                .withAk(huaWeiIotConfigProperties.getAk())
                .withSk(huaWeiIotConfigProperties.getSk());

        // 创建IoTDAClient对象，用于后续调用API接口
        IoTDAClient client = IoTDAClient.newBuilder()
                .withCredential(auth)
                // 标准版/企业版：需自行创建Region对象，基础版：请使用IoTDARegion的region对象，如"withRegion(IoTDARegion.CN_NORTH_4)"
                .withRegion(new Region(huaWeiIotConfigProperties.getRegionId(), huaWeiIotConfigProperties.getEndpoint()))
                .build();
        // 创建请求对象，用于后续调用API接口
        ListProductsRequest request = new ListProductsRequest();

            // 通过client客户端对象发送请求
            ListProductsResponse response = client.listProducts(request);
            // 打印响应信息
            System.out.println(response.toString());

    }
}